package game.farming.model;

import java.util.Stack;

public class Deck<E> extends Stack<E>{
	
	public Deck(){
		super();
		shuffle();
	}
	
	public void shuffle(){
		// Uses the Fisher_Yates shuffle algorithm
		Object temp;
		int tempIndex;
		for(int i = this.size() - 1; i >= 0; i--){
			tempIndex = ((int) (i * Math.random()));
			if(tempIndex != i){ //swap if different elements
				temp = this.get(i);
				this.set(i, this.get(tempIndex));
				this.set(tempIndex, (E) temp);
			}
		}
	}
	
}
